Moving Average from Data Stream

Given a stream of integers and a window size, calculate the moving average of all integers in the sliding window.

For example,

  1. MovingAverage m = new MovingAverage(3);
  2. m.next(1) = 1
  3. m.next(10) = (1 + 10) / 2
  4. m.next(3) = (1 + 10 + 3) / 3
  5. m.next(5) = (10 + 3 + 5) / 3
  6. Show Company Tags
  7. Show Tags